473,549 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pack and unpack

158 New Member
Ok what i am trying to do with my script i send a poll and receive a reply and read that reply. I have the Poll work properly but what i need help with is trying to convert the reply from ascii to regular text.

My reply consist of 30 different variables and i need them to be separated. my code so far is.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. print "Content-type:text/html\n\n";
  4. use IO::Socket;
  5.  
  6. #Poll
  7. my $header = 'Art-Net';
  8. my $space = ' ';
  9. my $Prover = chr(0x0e);
  10. my $filler = chr(0x00);
  11. my $ttm = chr(0x02);
  12. my $ID = $header.$filler;
  13.  
  14. my $ArtPoll = $ID.$filler.$space.$filler.$Prover.$ttm.$filler;
  15.  
  16.  
  17. #My Reply.
  18. my $T_ArtPollReply = pack("A8 S C C C C C C C C C S C18 C64 C64 C C C C C C C C C C C C C C C6 C32",
  19.     $ID,
  20.     $OpCode,
  21.     $BoxAddr,
  22.     $VersionInfoH,
  23.     $VersionInfo,
  24.     $SubSwitchH,
  25.     $SubSwitch,
  26.     $OemH,
  27.     $Oem,
  28.     $UbeaVersion,
  29.     $Status,
  30.     $EstaMan,
  31.     $ShortName,
  32.     $LongName,
  33.     $NodeReport,
  34.     $NumPortsH,
  35.     $NumPorts,
  36.     $PortTypes,
  37.     $GoodInput,
  38.     $GoodOutput,
  39.     $Swin,
  40.     $Swout,
  41.     $SwVideo,
  42.     $SwMacro,
  43.     $SwRemote,
  44.     $Spare1,
  45.     $Spare2,
  46.     $Spare3,
  47.     $Style,
  48.     $Mac,
  49.     $Filler,
  50. );
  51.  
  52. $Node_Ip = '2.0.0.1';
  53.  
  54. my $poll = IO::Socket::INET->new(
  55.     PeerAddr    => $Node_Ip,
  56.     PeerPort    => "6454",
  57.     Proto        => "udp",
  58.     LocalPort    => "6454",
  59. );
  60.  
  61. sub ArtPoll {
  62.     $poll->send($ArtPoll);
  63.     print "ArtPoll sent.\n<hr>";
  64.  
  65.     sub Reply {
  66.         $poll->recv($T_ArtPollReply,250);
  67.         print $T_ArtPollReply;
  68.     }
  69.     &Reply;
  70. }
  71.  
  72. &ArtPoll;
  73.  
When i run it i try to print the reply but i get[HTML]<br>[/HTML] Art-Net??!??6? ??ÒLATest1??? ??????????Test Node ??????????????? ??????????????? ??????????????? ?????????#0001 [0019] Power On Tests Pass??????????? ??????????????? ???????€€????? ?€€?????????? ??????¦?

i know i have to do something with unpack or something but not sure if some one could help me out it would be very helpful.
Jun 13 '07 #1
0 1415

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2296
by: Johannes | last post by:
Hi, I tried to pack eight integer values and one string into one binary string, which I would like to store in a mysql db. I encountered two problems doing this: 1) $this->packed = pack('N8A*', $this->value1, $this->value2, $this->value3, $this->value4, $this->value5, $this->value6, $this->value7, $this->value8, $this->stringvalue);
2
3680
by: Sergey Dorofeev | last post by:
I can use string.unpack if string in struct uses fixed amount of bytes. But is there some extension to struct modue, which allows to unpack zero-terminated string, size of which is unknown? E.g. such struct: long, long, some bytes (string), zero, short, short, short.
4
15590
by: Stacy Mader | last post by:
Greetings all, I have a VMS binary file with weather data. The record on each line is 1xint(8) 12xint(2) Using the perl unpack function, I can decode the binary file like this: <snip>
18
7545
by: p.lavarre | last post by:
Can Python not express the idea of a three-byte int? For instance, in the working example below, can we somehow collapse the three calls of struct.pack into one? 08 12 34 56 80 00 I ask because I'm trying to refactor working code that is concise: 08 12 34 56 80 00
0
1349
by: Steve | last post by:
Are there any gurus of the pack/unpack world out there that can help me with this one? I have an encrypted string which I'm reading from a zipped file. It was written using pack ( "la" . strlen (encrypted), strlen (encrypted), strlen (encrypted)) most of the time, it decrypts correctly when I unpack as...
5
1718
by: andmarti | last post by:
If I build a strict with: import struct print struck.pack ('i', 1) it returns a '\n'. What's wrong with it??? :( --
1
7987
by: praveen0437 | last post by:
hi i know about format argument in pack and unpack like b h i etc but in some cases i am getting < or = symbols along with them what does they signifies for example struct.pack( "<cI", 'n', var1 )
5
7309
by: tmp123 | last post by:
Hello, Thanks for your time. After review the "struct" documentation, it seems there are no option to pack/unpack zero terminated strings. By example, if the packed data contains: byte + zero terminated string + zero terminated string + byte, it seems no possible to unpack it using "struct".
1
3146
by: joe shoemaker | last post by:
If you have the following: data = unpack('>L', sock.recv(4)) Does this line of code means that incoming data is big endian and unpack it to endianess of local machine? If local machine is little endian, then big endian is automatically converted to little endian format? thank you.
0
7548
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7472
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5391
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5114
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3518
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3499
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1965
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1083
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.